<template>
  <view class="address-item" :class="{default: address.isDefault}">
    <view class="address-content" @click="$emit('select')">
      <view class="address-header" v-if="address.isDefault">
        <uni-icons type="star-filled" size="16" color="$primary-color"></uni-icons>
        <text class="default-text">默认地址</text>
      </view>
      
      <view class="address-info">
        <view class="name-phone">
          <text class="name">{{address.name}}</text>
          <text class="phone">{{address.phone}}</text>
        </view>
        <text class="address-detail">{{address.province}}{{address.city}}{{address.district}}{{address.detail}}</text>
      </view>
    </view>
    
    <view class="address-actions" v-if="!selectMode">
      <view class="action-edit" @click="$emit('edit')">
        <uni-icons type="compose" size="20" color="#666"></uni-icons>
        <text>编辑</text>
      </view>
      <view class="action-delete" @click="$emit('delete')">
        <uni-icons type="trash" size="20" color="#ff4d4f"></uni-icons>
        <text>删除</text>
      </view>
    </view>
  </view>
</template>

<script setup>
defineProps({
  address: {
    type: Object,
    required: true
  },
  selectMode: {
    type: Boolean,
    default: false
  }
})

defineEmits(['edit', 'delete', 'select'])
</script>

<style lang="scss">
.address-item {
  background-color: $white-bg;;
  margin-bottom: 20rpx;
  border-radius: 12rpx;
  overflow: hidden;
  position: relative;
  
  &::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 8rpx;
    background-color: #f5f5f5;
  }
  
  &.default {
    &::before {
      background-color: $primary-color;
    }
    
    .address-header {
      display: flex;
    }
  }
  
  .address-content {
    padding: 30rpx;
    
    .address-header {
      display: none;
      align-items: center;
      margin-bottom: 15rpx;
      
      .default-text {
        font-size: 24rpx;
        color: $primary-color;
        margin-left: 10rpx;
      }
    }
    
    .address-info {
      .name-phone {
        display: flex;
        align-items: center;
        margin-bottom: 15rpx;
        
        .name {
          font-size: $font-size-30rpx;
          font-weight: bold;
          margin-right: 20rpx;
        }
        
        .phone {
          font-size: $font-size-28rpx;
          color: $text-color-666;
        }
      }
      
      .address-detail {
        font-size: 26rpx;
        color: $text-color-666;
        line-height: 1.6;
      }
    }
  }
  
  .address-actions {
    display: flex;
    border-top: 1rpx dashed #f5f5f5;
    
    > view {
      flex: 1;
      display: flex;
      justify-content: center;
      align-items: center;
      padding: 20rpx 0;
      
      .uni-icons {
        margin-right: 10rpx;
      }
      
      text {
        font-size: 26rpx;
      }
    }
    
    .action-edit {
      border-right: 1rpx dashed #f5f5f5;
      color: $text-color-666;
    }
    
    .action-delete {
      color: #ff4d4f;
    }
  }
}
</style>